﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection.Emit;
using System.Reflection;

namespace Fabs.Net.GIL
{
    public class Constructor : IFunction
    {
        public Constructor()
        {
            ParameterTypes = new List<Type>();
            Attributes = new List<MethodAttributes>();
        }

         public ConstructorBuilder Output { get; private set; }

        public void Compile(Class Parent)
        {
            var parent = Parent.Output;

            MethodAttributes attributes = Attributes[0];
            for (int i = 1; i < Attributes.Count; i++)
            {
                attributes |= Attributes[i];
            }

            Type objectType = Type.GetType("System.Object");
            ConstructorInfo objectConstructorInfo = objectType.GetConstructor(new Type[0]);

            ConstructorBuilder output = parent.DefineConstructor(attributes, CallingConventions.Standard, ParameterTypes.ToArray());
            Emit(Parent, objectConstructorInfo);
        }

        private void Emit(Class Parent, ConstructorInfo objectConstructorInfo)
        {
            // yapılajak
        }
    }
}